package com.school.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.school.system.domain.Course;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.school.common.annotation.Log;
import com.school.common.core.controller.BaseController;
import com.school.common.core.domain.AjaxResult;
import com.school.common.enums.BusinessType;
import com.school.system.domain.SelectCourse;
import com.school.system.service.ISelectCourseService;
import com.school.common.utils.poi.ExcelUtil;
import com.school.common.core.page.TableDataInfo;

/**
 * 选课信息表Controller
 *
 * @author fulin
 * @date 2023-03-09
 */
@RestController
@RequestMapping("/system/course/select")
public class SelectCourseController extends BaseController
{
    @Autowired
    private ISelectCourseService selectCourseService;

    /**
     * 查询选课信息表列表
     */
    @PreAuthorize("@ss.hasPermi('system:select:course:list')")
    @GetMapping("/list")
    public TableDataInfo list(SelectCourse selectCourse)
    {
        startPage();
        List<Course> list = selectCourseService.selectSelectCourseList(selectCourse);
        return getDataTable(list);
    }

    /**
     * 导出选课信息表列表
     */
    @PreAuthorize("@ss.hasPermi('system:select:course:export')")
    @Log(title = "选课信息表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SelectCourse selectCourse)
    {
        List<Course> list = selectCourseService.selectSelectCourseList(selectCourse);
        ExcelUtil<Course> util = new ExcelUtil<Course>(Course.class);
        util.exportExcel(response, list, "选课信息表数据");
    }

    /**
     * 获取选课信息表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:select:course:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(selectCourseService.selectSelectCourseById(id));
    }

    /**
     * 新增选课信息表
     */
    @PreAuthorize("@ss.hasPermi('system:select:course:select')")
    @Log(title = "选课信息表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody String id)
    {
        return selectCourseService.insertSelectCourse(id);
    }

    /**
     * 申请退回选课信
     */
    @PreAuthorize("@ss.hasPermi('system:select:course:back')")
    @Log(title = "选课信息表", businessType = BusinessType.BACK)
    @PostMapping("/back")
    public AjaxResult back(@RequestBody String id)
    {
        return selectCourseService.backSelectCourse(id);
    }

    /**
     * 审核退回选课信
     */
    @PreAuthorize("@ss.hasPermi('system:select:course:audit')")
    @Log(title = "选课信息表", businessType = BusinessType.BACK)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody String id,@RequestBody int status)
    {
        return selectCourseService.auditSelectCourse(id,status);
    }

    /**
     * 修改选课信息表
     */
    @PreAuthorize("@ss.hasPermi('system:select:course:edit')")
    @Log(title = "选课信息表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SelectCourse selectCourse)
    {
        return toAjax(selectCourseService.updateSelectCourse(selectCourse));
    }

    /**
     * 删除选课信息表
     */
    @PreAuthorize("@ss.hasPermi('system:select:course:remove')")
    @Log(title = "选课信息表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(selectCourseService.deleteSelectCourseByIds(ids));
    }
}
